<template>
  <div class="child">
    <el-form label-width="60px">
      <el-form-item label="手机号" prop="phone">
        <el-input />
      </el-form-item>
      <el-form-item label="验证码" prop="code">
        <div class="get-code">
          <el-input />
          <el-button
            type="primary"
            class="get-btn"
            :disabled="disabled"
            @click="getCode"
          >
            {{ btnContent.content }}
          </el-button>
        </div>
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive } from 'vue'

const btnContent = reactive({
  content: '获取验证码',
  time: 60
})
const disabled = ref(false)
const getCode = () => {
  let timer = setInterval(() => {
    btnContent.time--
    btnContent.content = btnContent.time + 's后再次发送'
    disabled.value = true
    if (btnContent.time <= 0) {
      clearInterval(timer)
      btnContent.content = `获取验证码`
      disabled.value = false
    }
  }, 1000)
}
</script>
<style scoped>
.get-code {
  display: flex;
}
.get-btn {
  margin-left: 8px;
}
</style>
